import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Form';
import { useI18n } from '/@/hooks/web/useI18n';

import { getCodeList, GetBdAllPropertyTeam, GetBdGroupNameList } from '/@/api/demo/system';

const { t } = useI18n();

export function getFormSettingColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.FigureDocSettings.figureDocTypeId'),
      dataIndex: 'id',
      width: 200,
      fixed: 'left',
    },
    {
      title: t('routes.demo.FigureDocSettings.figureDocTypeName'),
      dataIndex: 'name',
      width: 200,
    },
    {
      title: t('routes.demo.FigureDocSettings.codingSystemAssociation'),
      dataIndex: 'counterID',
      width: 200,
    },
  ];
}

export function getFormSetProperty(isUpdate): FormSchema[] {
  return [
    {
      field: 'oId',
      component: 'Input',
      required: true,
      label: t('routes.demo.FigureDocSettings.figureDocTypeId'),
      componentProps: {
        placeholder: t('routes.demo.FigureDocSettings.figureDocTypeIdPlaceholder'),
      },
      dynamicDisabled: () => {
        return isUpdate.value;
      },
      // 禁止输入汉字
      rules: [
        {
          pattern: /^[a-zA-Z][^\u4e00-\u9fa5]*$/,
          message: t('routes.demo.FigureDocSettings.figureDocTypeIdRule'),
        },
      ],
    },
    {
      field: 'name',
      component: 'Input',
      required: true,
      label: t('routes.demo.FigureDocSettings.figureDocTypeName'),
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.FigureDocSettings.figureDocTypeNamePlaceholder'),
      },
    },
    {
      field: 'counterID',
      component: 'ApiSelect',
      label: t('routes.demo.FigureDocSettings.codingSystemAssociation'),
      componentProps: {
        api: getCodeList,
        placeholder: t('routes.demo.FigureDocSettings.codingSystemAssociationPlaceholder'),
        labelField: 'remark',
        valueField: 'counterID',
      },
    },
    {
      field: 'createSoft',
      component: 'Input',
      label: t('routes.demo.FigureDocSettings.producingSoftware'),
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.FigureDocSettings.producingSoftwarePlaceholder'),
      },
    },
    {
      field: 'check1',
      component: 'Checkbox',
      defaultValue: false,
      componentProps: {
        disabled: true,
      },
      label: t('routes.demo.FigureDocSettings.partAttachment'),
      colProps: {
        span: 6,
      },
      itemProps: {
        labelCol: {
          span: 16,
        },
        wrapperCol: {
          span: 6,
        },
      },
    },
    {
      field: 'check2',
      component: 'Checkbox',
      defaultValue: false,
      componentProps: {
        disabled: true,
      },
      label: t('routes.demo.FigureDocSettings.threeDimensionalData'),
      colProps: {
        span: 6,
      },
      itemProps: {
        labelCol: {
          span: 16,
        },
        wrapperCol: {
          span: 6,
        },
      },
    },
    {
      field: 'check3',
      component: 'Checkbox',
      defaultValue: false,
      componentProps: {
        disabled: true,
      },
      label: t('routes.demo.FigureDocSettings.oneFigureManyParts'),
      colProps: {
        span: 6,
      },
      itemProps: {
        labelCol: {
          span: 16,
        },
        wrapperCol: {
          span: 6,
        },
      },
    },
    {
      field: 'check4',
      component: 'Checkbox',
      defaultValue: false,
      componentProps: {
        disabled: true,
      },
      label: t('routes.demo.FigureDocSettings.generateDrawingFrame'),
      colProps: {
        span: 6,
      },
      itemProps: {
        labelCol: {
          span: 16,
        },
        wrapperCol: {
          span: 6,
        },
      },
    },
    {
      field: 'check5',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.FigureDocSettings.craftFile'),
      colProps: {
        span: 6,
      },
      itemProps: {
        labelCol: {
          span: 16,
        },
        wrapperCol: {
          span: 6,
        },
      },
    },
    {
      field: 'check6',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.FigureDocSettings.browsePdfFile'),
      colProps: {
        span: 6,
      },
      itemProps: {
        labelCol: {
          span: 16,
        },
        wrapperCol: {
          span: 6,
        },
      },
    },
    {
      field: 'template',
      component: 'Divider',
      label: '图文档id',
      defaultValue: 'none',
      show: false,
    },
    {
      field: 'Divider',
      component: 'Divider',
      label: t('routes.demo.FigureDocSettings.sourceFileStorageWay'),
    },
    {
      field: 'sourceFileStorageWay',
      component: 'RadioGroup',
      label: '',
      defaultValue: '0',
      componentProps: {
        options: [
          { label: t('routes.demo.FigureDocSettings.databaseStorage'), value: '0' },
          { label: t('routes.demo.FigureDocSettings.ftpStorage'), value: '1' },
        ],
      },
      dynamicDisabled: () => {
        return isUpdate.value;
      },
    },
    {
      field: 'datavault',
      component: 'Input',
      label: t('routes.demo.FigureDocSettings.ftpStorage'),
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.FigureDocSettings.ftpStoragePlaceholder'),
      },
      dynamicDisabled: (params) => {
        return isUpdate.value || params.values.sourceFileStorageWay === '0' ? true : false;
      },
    },
  ];
}

export function getClassColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.partSetting.propertyId'),
      dataIndex: 'prop',
      width: 150,
      fixed: 'left',
    },
    {
      title: t('routes.demo.partSetting.propertyName'),
      dataIndex: 'name',
      align: 'center',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.dataType'),
      dataIndex: 'dataType',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.length'),
      dataIndex: 'length',
      width: 100,
    },
    {
      title: t('routes.demo.partSetting.control'),
      dataIndex: 'attr',
      width: 120,
      slots: { customRender: 'attr' },
    },
    {
      title: t('routes.demo.partSetting.order'),
      dataIndex: 'dispIndex',
      width: 100,
    },
    {
      title: t('routes.demo.partSetting.optionalValue'),
      dataIndex: 'defaultValue',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.allowEmpty'),
      dataIndex: 'pdmnull',
      width: 100,
      slots: { customRender: 'pdmnull' },
    },
    {
      title: t('routes.demo.partSetting.isSensitiveProperty'),
      dataIndex: 'isOnly',
      width: 100,
      slots: { customRender: 'isOnly' },
    },
  ];
}

export function getFormClassProp(isUpdate, canChange): FormSchema[] {
  return [
    {
      field: 'prop',
      component: 'Input',
      label: t('routes.demo.partSetting.propertyId'),
      required: true,
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.partSetting.propertyIdPlaceholder'),
      },
      dynamicDisabled: () => {
        return canChange.value === '0' || canChange.value === '1';
      },
      rules: [
        {
          required: true,
          message: t('routes.demo.partSetting.propRule'),
          pattern: /^[a-zA-Z]/,
          trigger: 'blur',
        },
      ],
    },
    {
      field: 'name',
      component: 'Input',
      label: t('routes.demo.partSetting.propertyName'),
      required: true,
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.partSetting.propertyNamePlaceholder'),
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'dataType',
      component: 'Select',
      label: t('routes.demo.partSetting.dataType'),
      required: true,
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.partSetting.dataTypePlaceholder'),
        options: [
          {
            label: t('routes.demo.FigureDocSettings.varchar'),
            value: 'varchar',
          },
          {
            label: t('routes.demo.FigureDocSettings.datetime'),
            value: 'datetime',
          },
          {
            label: t('routes.demo.FigureDocSettings.int'),
            value: 'int',
          },
          {
            label: t('routes.demo.FigureDocSettings.float'),
            value: 'float',
          },
          {
            label: t('routes.demo.FigureDocSettings.boolean'),
            value: 'bool',
          },
          // {
          //   label: t('routes.demo.FigureDocSettings.joint'),
          //   value: 'joint',
          // },
          // {
          //   label: t('routes.demo.FigureDocSettings.dataext'),
          //   value: 'dataext',
          // },
        ],
      },
      dynamicDisabled: () => {
        return canChange.value === '0' || canChange.value === '1';
      },
    },
    {
      field: 'length',
      component: 'Input',
      label: t('routes.demo.partSetting.length'),
      required: true,
      defaultValue: '64',
      componentProps: {
        placeholder: t('routes.demo.partSetting.lengthPlaceholder'),
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'attr',
      component: 'Select',
      label: t('routes.demo.partSetting.control'),
      required: true,
      defaultValue: '256',
      componentProps: {
        placeholder: t('routes.demo.partSetting.controlPlaceholder'),
        options: [
          {
            label: t('routes.demo.FigureDocSettings.text'),
            value: '256',
          },
          {
            label: t('routes.demo.FigureDocSettings.select'),
            value: '640',
          },
          {
            label: t('routes.demo.FigureDocSettings.selectDataSource'),
            value: '131072',
          },
          {
            label: t('routes.demo.FigureDocSettings.multipleSelect'),
            value: '32768',
          },
          {
            label: t('routes.demo.FigureDocSettings.associatedFile'),
            value: '262144',
          },
          {
            label: t('routes.demo.FigureDocSettings.calendar'),
            value: '8448',
          },
          {
            label: t('routes.demo.FigureDocSettings.resource'),
            value: '1024',
          },
          {
            label: t('routes.demo.FigureDocSettings.resourceMultiple'),
            value: '768',
          },
          {
            label: t('routes.demo.FigureDocSettings.selectBox'),
            value: '16384',
          },
          {
            label: t('routes.demo.FigureDocSettings.grid'),
            value: '512',
          },
        ],
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'dispIndex',
      component: 'Input',
      label: t('routes.demo.partSetting.order'),
      required: true,
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.partSetting.orderPlaceholder'),
      },
      dynamicDisabled: () => {
        return !isUpdate.value;
      },
    },
    {
      field: 'gridname',
      component: 'ApiSelect',
      label: t('routes.demo.partSetting.gridGroup'),
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.partSetting.gridGroupPlaceholder'),
        api: GetBdGroupNameList,
        params: localStorage.getItem('BdGroupNameID'),
      },
      dynamicDisabled: (params) => {
        return (
          canChange.value === '0' || params.values.attr !== '640' || params.values.attr !== '512'
        );
      },
    },
    {
      field: 'attrgroup',
      component: 'ApiSelect',
      label: t('routes.demo.partSetting.group'),
      required: true,
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.partSetting.groupPlaceholder'),
        api: GetBdAllPropertyTeam,
        labelField: 'name',
        valueField: 'id',
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'defaultValue',
      component: 'InputTextArea',
      helpMessage: t('routes.demo.partSetting.optionalValueSplit'),
      label: t('routes.demo.partSetting.optionalValue'),
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.partSetting.optionalValuePlaceholder'),
      },
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'pdmnull',
      component: 'Checkbox',
      defaultValue: true,
      label: t('routes.demo.partSetting.allowEmpty'),
      dynamicDisabled: () => {
        return canChange.value === '0' || canChange.value === '1';
      },
    },
    {
      field: 'readOnly',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.partSetting.readOnly'),
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
    {
      field: 'isOnly',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.partSetting.isSensitiveProperty'),
      dynamicDisabled: () => {
        return canChange.value === '0';
      },
    },
  ];
}

export function getAttrGroupColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.table.formManagement.name'),
      dataIndex: 'name',
      width: 150,
    },
  ];
}
